import storage from '@/utils/storage'
export default {
    state: {
        history: storage.getItem('searchHistory') || []
    },
    mutations: {
        setHistory (state, val) {
            if (state.history.indexOf(val) !== -1) return
            const temp = storage.getItem('searchHistory') || []
            if (val) storage.setItem({ searchHistory: [...temp, val] })
            state.history = storage.getItem('searchHistory') || []
        },
        clearHistory (state) {
            storage.removeItem('searchHistory')
            state.history = []
        }
    }
}
